<!DOCTYPE html>
<html>

<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="no-cache, no-store, must-revalidate"
	http-equiv="Cache-Control" />
<meta content="no-cache" http-equiv="Pragma" />
<meta content="0" http-equiv="Expires" />
<title></title>
<link rel="stylesheet" href="../styles/base.css" />
<link rel="stylesheet" href="../styles/common.css" />
<link rel="stylesheet" href="../styles/jquery.multiselect.filter.css" />
<link rel="stylesheet" href="../styles/jquery.multiselect.css" />
<link rel="stylesheet" href="../jqueryNicepage/css/layui.css"
	media="all">
<link rel="stylesheet" href="../styles/font/iconfont.css" />
<style>
* {
	margin: 0;
	padding: 0px;
}

#bodyStyle {
	background: #ddecf5;
	overflow: hidden;
}

.formContent {
	height: auto;
	/* overflow-y: scroll;*/
}

.formContent center {
	margin-top: -10px;
}

.formContent center #table {
	max-height: 70%;
	width: 100%;
}

.formContent center #pageBar {
	position: absolute;
	top: 0px;
	margin-left: -10%;
	text-align: center;
}

#bodyStyle .searchContainer {
	max-height: 96%;
	width: 90%;
	margin-top: 5px;
	margin-left: 5%;
}

.seachHeader .headerLeft {
	/* width: 40%; */
	margin-left: 5px;
}

.seachHeader .headerRight {
	/* width: 55%; */
}

#select_ms {
	/* left: 200px; */
	margin-top: 5px;
	height:30px;
	line-height: 30px;
	margin-left: 20px;
	position:relative; 
}

.selectBox {
	position: relative;
}

.selectBox ul {
	position: absolute;
	z-index: 999999;
	background: #fff;
	border: 1px solid #ccc;
	width: 150px;
	height: auto;
	display: none;
	left: 131px;
}

.selectBox ul li {
	width: 140px;
	height: 30px;
	line-height: 30px;
	font-size: 14px;
	padding-left: 10px;
}

.selectBox ul li:hover {
	background: #f2f2f2;
}

.selectInline {
	display: inline-block;
	height: 30px;
	margin: 10px;
}

.selectInline #select {
	width: 150px;
	height: 30px;
	line-height: 30px;
	font-size: 14px;
	/*  border-color:#ddd;*/
	outline: none;
	box-sizing: border-box;
}

/* .selectInline span {
            display: inline-block;
            box-sizing: border-box;
            border: 1px solid #ccc;
            height: 30px;
            margin-right: 10px;
            line-height: 30px;
            margin-left: 3px;
            margin-top: 2px;
            padding:10px;
        } */
.selectInline span:nth-last-child(1) {
	border: none;
}

#searchInput2 {
	height: 30px;
	font-size: 14px;
	line-height: 30px;
}

.seachHeader{
    padding-bottom: 10px;
}
.headerLeft{
    width:auto;
    float:none;
}
.headerLeft .searchBtnBatch{
    float:none; 
 }
</style>
<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
</head>

<body id="bodyStyle">
	<div id="loading">
		<img src='../styles/img/loading.gif' />
	</div>
	<div class="searchContainer">
		<!--<span class="selectInline">  -->
		<div class="seachHeader">
			<div class="selectBox selectInline" style="font-size: 16px;">
				<span>请选择查询类型：</span> <span><input readonly="readonly"
					unselectable="on" type="text" placeholder="--请选择--" id="select2"
					style="width: 120px; height: 30px; border: 1px solid;"></span>
				<ul name="" id="selectList" style="display: none;">
					<li></li>
					<li id="referencePart">根据参考料号查询</li>
					<li id="effectPart">查询受影响对象</li>
				</ul>
				<span style="margin-left: 20px;">请输入对应编号：</span> 
				<span> 
					<input maxlength="50" type="text" placeholder="请输入对应编号" id="searchInput"
					style="border: 1px solid; width: 138px; height: 30px;">
				</span>
				
				<select id="select" multiple="multiple" style="display: none;"></select>
				<!-- <button type="button" class="ui-multiselect ui-widget ui-state-default ui-corner-all" id="select_ms"
					style="height: 30px; margin-left: 20px; width: 225px;">
					<span class="ui-icon ui-icon-triangle-1-s"></span><span>==请选择视图==</span>
				</button> -->
				
				<span style="margin-left: 20px;">模糊查询：</span> 
				<span>
					<input maxlength="50" placeholder="例如*TM或者TM*" id="fuzzyMatching" type="text"
					style="border: 1px solid; width: 120px; height: 30px; line-height: 30px;">
				</span> 
				
				<span class="headerLeft headerContent headerRight" style="margin: 0px; height: 30px;width: auto;float: none;">
					<button class="submitData searchBtnBatch" style="margin-left: 20px;">提交</button>
					<button class="searchSureBtnBatch searchBtnBatch">搜索</button>
				</span>
			</div>
		</div>

		<div class="formContent"></div>
	</div>
</body>
<script type="text/javascript" src="../js/constants/formBox.js"></script>
<script src="../layer/layer.js" charset="utf-8"></script>
<script type="text/javascript" src="../js/common/myAjax.js"></script>
<script type="text/javascript" src="../js/common/utils.js"></script>
<script type="text/javascript" src="../js/common/jquery-ui.min.js"></script>
<script type="text/javascript" src="../js/common/jquery.multiselect.js"></script>
<script>
    $(function () {
    	 //查询类型
        var selectType = "";
        //获取地址栏参数
        getUrlParam(location.href);
        var dataLists = [];
        var ecoid = getQueryStringByNameTwo("oid");
        var urldataList = getQueryStringByNameTwo('urldataList');
        
        //设置查询料号
        if(urldataList != undefined){
        	document.getElementById("searchInput").value = urldataList;
        }
        //设置默认类型 为根据参考料号查询
        $("#select2").val("根据参考料号查询");
        $("#selectList").css({
            "display": "none"
        });
        selectType = "referencePart";
        //end
        var datUrl = urldataList != "" && urldataList != undefined ? urldataList : "";
        var textsArr = [];
        // var dataL=[];
        var initIputVal = "";
        var inintArr = [];

        //初始化下拉框
        var heightx = document.body.clientHeight;
        var widthx = document.body.clientWidth;
        $("#loading img").css({
            "margin-left": (widthx / 2 - 25) + "px",
            "margin-top": (heightx / 2 - 25) + "px"
        })
        $('#select').multiselect({
        	
            noneSelectedText: "==请选择视图==",
            checkAllText: "全选",
            uncheckAllText: '全不选',
            selectedText: '# 个被选中',
            click: function (event, ui) {
                var oHeight = $("#select_ms").height();
                $("#select_ms").css({
                    "overflow": "hidden",
                    "white-space": "nowrap",
                    "text-overflow": "ellipsis"
                })
                if (ui.checked) {
                    textsArr.push(ui.text)
                } else {
                    var index;
                    if (!textsArr.indexOf) {
                        textsArr.indexOf = function (elt /*, from*/ ) {
                            var len = this.length >>> 0;
                            var from = Number(arguments[1]) || 0;
                            from = (from < 0) ?
                                Math.ceil(from) :
                                Math.floor(from);
                            if (from < 0)
                                from += len;
                            for (; from < len; from++) {
                                if (from in this &&
                                    this[from] === elt)
                                    return from;
                            }
                            return -1;
                        };
                        index = textsArr.indexOf(ui.text);
                    } else {
                        index = textsArr.indexOf(ui.text);
                    }

                    if (index > (-1)) {
                        textsArr.splice(index, 1);
                    }
                }
            },
            selectedList: 4
        });
        
        $("#select_ms").css({
            "position":"relative"
        })

        function getSelectData(datas) {
            $("#select").empty();
            for (var dat = 0; dat < datas.length; dat++) {
                var option = "<option value=" + dat + ">" + datas[dat].view + "</option>";
                $("#select").append(option);
            }
            $("#select").multiselect('refresh');
        }
        $(".headerContent input").eq(0).val(datUrl);
        //搜索按钮点击请求
        $(".ui-multiselect").click(function (e) {
            setAjaxFn();
            window.event ? window.event.cancelBubble = true : e.stopPropagation();
        })
        $(".ui-multiselect span").click(function (e) {
            setAjaxFn();
            window.event ? window.event.cancelBubble = true : e.stopPropagation();
        })
        window.onclick = function () {
            setAjaxFn();
        }

        function setAjaxFn() {
            var inputValue = $("#searchInput").val();
            var dataL = [];
            var valArr = [];
            if (getIndexof(inputValue, ";") > 0) {
                valArr = inputValue.split(";")
            } else if (getIndexof(inputValue, "；") > 0) {
                valArr = inputValue.split("；")
            } else if (getIndexof(inputValue, "/") > 0) {
                valArr = inputValue.split("/")
            } else if (getIndexof(inputValue, ",") > 0) {
                valArr = inputValue.split(",")
            } else if (getIndexof(inputValue, "，") > 0) {
                valArr = inputValue.split("，")
            } else {
                valArr.push(inputValue);
            }

            for (var i = 0; i < valArr.length; i++) {
                var obj = {};
                obj.partnumber = valArr[i];
                obj.ecoid = ecoid;
                dataL.push(obj);
            }
            var url = "/tmEcoSingleSearch",
                data = {
                    datalist: dataL
                };
            if ($("#searchInput").val() != "" && initIputVal != $("#searchInput").val()) {
            	//查询类型
                var querytype = "0";
            	if (selectType != undefined && selectType != '' && selectType == 'referencePart') {
                    querytype = "1";
                } else if (selectType != undefined && selectType != '' && selectType == 'effectPart') {
                    querytype = "0";
                } 
            	
                initIputVal = $("#searchInput").val();
                myAjax(url, data, blurSucCallback, errCallback, querytype);
                $("#loading").css({
                    display: "block"
                });
                var height = document.body.clientHeight;
                var width = document.body.clientWidth;
                $("#loading img").css({
                    "margin-left": width / 2 - 25 + "px",
                    "margin-top": height / 2 - 25 + "px"
                })
            } else if ($("#searchInput").val() == "") {
                textsArr = [];
                initIputVal = "";
                $("#select").empty();
                $("#select").multiselect('refresh');
            }
        }
        $("#searchInput").blur(function (e) {
            setAjaxFn();
            window.event ? window.event.cancelBubble = true : e.stopPropagation();

        })

        function blurSucCallback(str) {
            textsArr = [];
            $("#loading").css({
                display: "none"
            });
            if (str.result != '' && str.result != undefined) {
                layerFn(str.result);
            }
            if (str.datalist.length > 0) {
                dataLists = str.datalist;
                getSelectData(str.datalist);

            } else {
                if (str.length == 0 && str.datalist.length == 0 && str.result == '') {
                    layerFn("您查询的数据在非Design视图中不存在");
                }
            }

        }
        $(".searchSureBtnBatch").unbind("click").click(function (e) {
            if ($("#fuzzyMatching").val() != "" && window.objV != undefined && window.objV.length > 0) {
                var val = $("#fuzzyMatching").val();
                var rexg = /\*/g;
                // console.log(rexg.test(val));
                if (rexg.test(val) && val.length > 1) {
                    val = val.replace(rexg, "")
                    window.objV = searchData(val, window.objV, "number");
                    if (window.objV.length > 0) {
                        toShowData();
                    } else {
                        layerFn("筛选的数据不存在")
                    }

                    //console.log(window.objV);
                } else if (rexg.test(val) && val.length == 0) {
                    layerFn("输入格式错误，应输入例如*TM或者TM*")
                    return;
                }

            } else {
                window.event ? window.event.cancelBubble = true : e.stopPropagation();
                //查询类型
                var querytype = "0";

                var dataL = [];
                var valArr = [];
                var inputValue = $("#searchInput").val();
                /*   alert("搜索 searchInput:"+inputValue.length);
                  alert("搜索 selectType:"+selectType); */
                //根据参考料号查询
                if (selectType != undefined && selectType != '' && selectType == 'referencePart') {
                    querytype = "1";
                } else if (selectType != undefined && selectType != '' && selectType == 'effectPart') {
                    querytype = "0";
                } else if (selectType == undefined || selectType == '') {
                    layerFn("请选择查询类型");
                    return;
                }
                if (inputValue.length == 0 || inputValue == '') {
                    layerFn("请输入查询编号");
                    return;
                }
                /*  alert("搜索 处理后 querytype:"+querytype); */
                if (getIndexof(inputValue, ";") > 0) {
                    valArr = inputValue.split(";")
                } else if (getIndexof(inputValue, "；") > 0) {
                    valArr = inputValue.split("；")
                } else if (getIndexof(inputValue, "/") > 0) {
                    valArr = inputValue.split("/")
                } else if (getIndexof(inputValue, ",") > 0) {
                    valArr = inputValue.split(",")
                } else if (getIndexof(inputValue, "，") > 0) {
                    valArr = inputValue.split("，")
                } else {
                    valArr.push(inputValue);
                }
                for (var i = 0; i < valArr.length; i++) {
                    var obj = {};
                    obj.partnumber = valArr[i];
                    obj.ecoid = ecoid;
                    dataL.push(obj);
                }
                var dataList = [];
                if (dataL.length > 0 && textsArr.length > 0) {
                    for (var i = 0; i < textsArr.length; i++) {
                        for (var j = 0; j < dataL.length; j++) {
                            var obj = {
                                partnumber: dataL[j].partnumber,
                                ecoid: ecoid,
                                view: textsArr[i]
                            }
                            dataList.push(obj);
                        }
                    }
                } else if (textsArr.length == 0) {
                    dataList = dataL;
                }
                if (dataList.length > 0) {
                    var url = "/tmEcoSingleSearch",
                        data = {
                            ecoid: ecoid,
                            datalist: dataList //string
                        };
                    /*  myAjax(url,data,suCallback,errCallback,"1"); */
                    myAjax(url, data, suCallback, errCallback, querytype);
                    $("#loading").css({
                        display: "block"
                    });
                }
                return false;
            }

        })
        //数据请求成功的回调函数
        function suCallback(result) {
            // result=eval(result);
            var datass = [];
            $(".defaultText").css("display", "none")
            if (result.result != '' && result.result != undefined) {
                layerFn(result.result);
            }
            if (result.datalist.length > 0) {
                var datArr = [];
                for (var v in result.datalist) {
                    datArr.push(result.datalist[v].number)
                }
                datArr = datArr.sort();
                for (var d = 0; d < datArr.length; d++) {
                    for (var c = 0; c < result.datalist.length; c++) {
                        if (datArr[d] == result.datalist[c].number) {
                            datass.push(result.datalist[c]);
                        } else {}
                    }
                }
                dataLists = result.datalist;
                var dataObjArr = [];
                var objcV = {}
                for (var num = 0; num < dataLists.length; num++) {
                    objcV = {
                        number: dataLists[num].number,
                        view: dataLists[num].view,
                        state: dataLists[num].state,
                        version: dataLists[num].version
                    }
                    dataObjArr.push(objcV)
                }
                window.objV = dataObjArr.sort(compareDown(dataObjArr, "number"));
                toShowData();

            } else {
                $(".formContent").empty();
                if (result.datalist.length == 0 && result.result == '' && result.length == 0) {
                    layerFn("您查询的数据在非Design视图中不存在");
                }

            }

            $("#loading").css({
                display: "none"
            });
        }

        function errCallback(err) {
            $("#loading").css({
                display: "none"
            });
        }


        //下拉框点击赋值
        $("#selectList").on("click", "li", function (event) {
            var text = $(this).text();
            $("#select2").val(text);
            $("#selectList").css({
                "display": "none"
            });
            selectType = $(this).attr("id");
            event = event || window.event
            event.stopPropagation();
            return false;
        })
        //点击展示下拉列表
        $("#select2").click(function (e) {
            $("#selectList").css({
                "display": "block"
            })
            window.event ? window.event.cancelBubble = true : e.stopPropagation();
        })
        //点击空白隐藏下拉框
        window.onclick = function () {
            if ($("#selectList").css("display") == "block") {
                $("#selectList").css({
                    "display": "none"
                })
            }

        }
    })

    function toShowData() {
        window.headers = ["全选", "序号", "受影响对象料号" + "<i title='从大到小' class='iconfont up'>&#xe64d;</i>", "视图" +
            "<i title='从大到小' class='iconfont up'>&#xe64d;</i>", "受影响对象状态"
        ]
        window.widths = [100, 100, 200, 100, 100, 100];
        //在index页面渲染数据表格；
        $(".formContent").empty().load('./index.html', "", function () {
            $("#pageBar").css({
                "width": $(".searchContainer").width(),
                "text-align": "center",
                display: "block"
            });
            setTimeout(function () {
                var heightform = $(".searchContainer").height() - $(".seachHeader").height() - 20;
                /* console.log($(".layui-table").height());
                 console.log($(".formContent").height());*/
                if ($(".formContent")[0].offsetHeight > (heightform * 0.90)) {
                    $("#pageBar").css("top", heightform * 0.90 + $(".seachHeader").height() + 20)
                } else {
                    $("#pageBar").css("top", $(".formContent")[0].offsetHeight + $(".seachHeader")
                        .height() + 80);
                }
                $(".formContent").css({
                    "max-height": heightform * 0.90,
                    "overflow-y": "scroll"
                });
                clearTimeout();
            }, 200)
        });
    }
    $(".formContent").scroll(function () {
        var scrolltop = $(this).scrollTop();
        if (scrolltop > 0) {
            $("#table table thead").css({
                "position": "fixed",
                "background": "#f2f2f2",
                "opacity": "1",
                "z-index": 999,
                "top": "67px"
            })
        } else {
            $("#table table thead").css({
                "position": ""
            })
        }
        $("#table2 table thead tr").css({
            "width": $("#table2 table").width()

        })
        for (var i = 0; i < window.headers.length; i++) {
            var width = $("#table table tbody tr:first-child td").eq(i).width();
            $("#table .layui-table thead tr:first-child th").eq(i).css({
                "width": width + 1
            })
            if (IEVersion() > (8)) {
                $("#table .layui-table thead tr:first-child th").eq(i).css({
                    "width": width
                })
            } else if (IEVersion() == (8)) {
                $("#table .layui-table thead tr:first-child th").eq(i).css({
                    "width": width + 1
                })
            }


        }
    })
    $(window).resize(function () { //当浏览器大小变化时
        //console.log($("#table2 table").width())
        $("#table2 table thead tr").css({
            "width": $("#table2 table").width()

        })
    });
</script>

</html>